package com.asen.commons.core.base.listener;

import com.asen.commons.core.concurrent.GenericThreadPool;
//import com.asen.commons.utils.NacosUtils;
//import com.asen.commons.utils.RestUtils;
import com.asen.commons.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 全局事件发布处理器
 *
 * @author Gary
 * @version 1.0
 * @date 2022-07-29
 */
@Slf4j
@Component
// TODO
public class GlobalEventCaster {

    private final static String PUBLISH_EVENT_URL = "/inner/globalEvent/publishEvent";

    @Autowired
    private GenericThreadPool pool;

    public void castAsync(GlobalEventContext context) {
        //pool.executeQuietly(() -> castEvent(context));
    }

    private void castEvent(GlobalEventContext context) {
        //try {
        //    List<String> serviceList = NacosUtils.findServiceList();
        //    for (String service : serviceList) {
        //        try {
        //            RestUtils.post(StringUtils.lowerCase(service), PUBLISH_EVENT_URL, context, null);
        //        } catch (Exception e) {
        //            log.warn("[GLOBAL_EVENT:IGNORE] cast event to [{}] error. {}", service, e.getMessage());
        //        }
        //    }
        //} catch (Exception e) {
        //    log.warn("[GLOBAL_EVENT:IGNORE] fetch service list error. {}", e.getMessage());
        //}
    }
}
